

package com.kimo.shop.admin.controller;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.PhoneUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kimo.shop.bean.model.NotifyLog;
import com.kimo.shop.bean.param.OrderParam;
import com.kimo.shop.common.util.PageParam;
import com.kimo.shop.service.NotifyLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


/**
 *
 *
 * @author kimo-taozhouchuan
 * @date 2020-08-10 15:20:53
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/notifyLog" )
public class NotifyLogController {

    @Value("${kimo.expose.permission:}")
    private Boolean permission;
    private final NotifyLogService notifyLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param notifyLog
     * @return 分页数据
     */
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('admin:notifyLog:list')" )
    public ResponseEntity<IPage<NotifyLog>> getNotifyLogPage(PageParam<NotifyLog> page, NotifyLog notifyLog, OrderParam orderParam) {
        IPage<NotifyLog> notifyLogPage = notifyLogService.pageByParam(page, orderParam);
        if (BooleanUtil.isFalse(permission)){
            for (NotifyLog record : notifyLogPage.getRecords()) {
                if (Objects.nonNull(record.getUserMobile())) {
                    record.setUserMobile(PhoneUtil.hideBetween(record.getUserMobile()).toString());
                }
            }
        }
        return ResponseEntity.ok(notifyLogPage);
    }


}
